package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.cache.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.cache.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis数据持久化
 */
//@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;

    @Autowired
    private IStrategyService strategyService;

    //Scheduled 定时任务标签
    //cron 任务计划表达式
    @Scheduled(cron = "0/8 * * * * ?") //一般6个就够了
    public void doWork(){
//        System.out.println("-------->"+System.currentTimeMillis());
        System.out.println("----------vo持久化------- start--------------");
        //1.查询Redis中所有的vo对象
       List<StrategyStatisVO> vos =  strategyStatisVORedisService.queryStrategyVoByPattern("*");
        //2.遍历vo对象update到MongoDB中去
        for (StrategyStatisVO vo : vos) {
            strategyService.updateStrategyVo(vo);
        }
        System.out.println("----------vo持久化------- end--------------");
    }
}
